package com.project.psc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.project.psc.bean.BiddConfirmBean;
import com.project.psc.bean.InviteSupplierBean;
import com.project.psc.bean.ReturnBean;
import com.project.psc.mapper.IBiddConfirmMapper;
import com.project.psc.mapper.IInviteMapper;
import com.project.psc.mapper.IInviteSupplierMapper;
import com.project.psc.mapper.IReturnMapper;
import com.project.psc.service.IMessageService;
import com.project.psc.vo.MessageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class MessageServiceImpl implements IMessageService {
    @Autowired
    private IInviteSupplierMapper inviteSupplierMapper;
    @Autowired
    private IReturnMapper returnMapper;
    @Autowired
    private IBiddConfirmMapper biddConfirmMapper;

    @Override
    public MessageVo findMsg(Long supplierId) {
        MessageVo messageVo=new MessageVo();

        //采购邀请消息
        QueryWrapper<InviteSupplierBean> qw = new QueryWrapper<>();
        qw.eq("fk_supplierId", supplierId);
        qw.eq("is_read", 0);
        boolean invite = inviteSupplierMapper.exists(qw);
        messageVo.setInvite(invite);

        //中标确认
        QueryWrapper<BiddConfirmBean> qw1=new QueryWrapper<>();
        qw1.eq("fk_supplierId", supplierId);
        qw1.eq("bc_read", 0);
        boolean confirm=biddConfirmMapper.exists(qw1);
        messageVo.setBiddConfirm(confirm);

        //退货
        QueryWrapper<ReturnBean> qw2=new QueryWrapper<>();
        qw2.eq("fk_supplierId", supplierId);
        qw2.ne("r_status",2);
        boolean returnGoods=returnMapper.exists(qw2);
        messageVo.setReturnGoods(returnGoods);

        return messageVo;
    }
}
